<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
/**
*  
*/
class BaseController extends Controller
{
	
	public function checkIndex()
	{
		if (Session::get('type') == 2) {
            return true;
        }
        return false;
	}
	/**
	 * 由于分页使用 
	 * @param  obiect $dbobject 实例化数据表
	 * @param  int   $page     当前页码
	 * @param  int $showrow  每页显示条数
	 * @return array          结果数组
	 */
    protected function getPagingData($dbobject,$page,$showrow){
        $total = $dbobject->count();
        if($total==0){
            //没有数据
            return array('msg'=>'nodata','status'=>'10','data'=>'');
        }
        $page=!empty($page)?$page:'1';
        $showrow=!empty($showrow)?$showrow:'5';
        //每页显示的条数
        $totalpage = ceil($total/$showrow);//总页数
        if($page>$totalpage){
            return array('msg'=>'nodata','status'=>'10','data'=>'');
        }
        $limit=($page-1)*$showrow.",".$showrow;     //每页的limit
        $result = $dbobject->limit($limit)->select();
        if(!empty($result)){
            $data['total']=$total;//总条数
            $data['totalpage']=$totalpage;//总页数
            $data['currentPage']=$page;//当前页数
            $data['data'] = $result;
            return array('msg'=>'ok','status'=>'1','data'=>$data);
        }else{
            return array('msg'=>'nodata','status'=>'10','data'=>'');
        }
    }
}